package com.tjy.farmer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tjy.common.annotation.Log;
import com.tjy.common.core.controller.BaseController;
import com.tjy.common.core.domain.AjaxResult;
import com.tjy.common.enums.BusinessType;
import com.tjy.farmer.domain.AreaBoundary;
import com.tjy.farmer.service.IAreaBoundaryService;
import com.tjy.common.utils.poi.ExcelUtil;
import com.tjy.common.core.page.TableDataInfo;

/**
 * 区域边界点Controller
 *
 * @author tjy
 * @date 2025-09-08
 */
@RestController
@RequestMapping("/farmer/boundary")
public class AreaBoundaryController extends BaseController {
    @Autowired
    private IAreaBoundaryService areaBoundaryService;

    /**
     * 查询区域边界点列表
     */
    @PreAuthorize("@ss.hasPermi('farmer:boundary:list')")
    @GetMapping("/list")
    public TableDataInfo list(AreaBoundary areaBoundary) {
        startPage();
        List<AreaBoundary> list = areaBoundaryService.selectAreaBoundaryList(areaBoundary);
        return getDataTable(list);
    }

    /**
     * 导出区域边界点列表
     */
    @PreAuthorize("@ss.hasPermi('farmer:boundary:export')")
    @Log(title = "区域边界点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AreaBoundary areaBoundary) {
        List<AreaBoundary> list = areaBoundaryService.selectAreaBoundaryList(areaBoundary);
        ExcelUtil<AreaBoundary> util = new ExcelUtil<AreaBoundary>(AreaBoundary.class);
        util.exportExcel(response, list, "区域边界点数据");
    }

    /**
     * 获取区域边界点详细信息
     */
    @PreAuthorize("@ss.hasPermi('farmer:boundary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(areaBoundaryService.selectAreaBoundaryById(id));
    }

    /**
     * 新增区域边界点
     */
    @PreAuthorize("@ss.hasPermi('farmer:boundary:add')")
    @Log(title = "区域边界点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AreaBoundary areaBoundary) {
        return toAjax(areaBoundaryService.insertAreaBoundary(areaBoundary));
    }

    /**
     * 修改区域边界点
     */
    @PreAuthorize("@ss.hasPermi('farmer:boundary:edit')")
    @Log(title = "区域边界点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AreaBoundary areaBoundary) {
        return toAjax(areaBoundaryService.updateAreaBoundary(areaBoundary));
    }

    /**
     * 删除区域边界点
     */
    @PreAuthorize("@ss.hasPermi('farmer:boundary:remove')")
    @Log(title = "区域边界点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(areaBoundaryService.deleteAreaBoundaryByIds(ids));
    }
}
